package com.imooc.set;

import java.util.ArrayList;
import java.util.Date;

public class NoticeTest {
    public static void main(String[] args){
        Notice notice1 = new Notice(1,"欢迎","管理员",new Date());
        Notice notice2 = new Notice(1,"交作业","老师",new Date());
        Notice notice3 = new Notice(1,"得分","老师",new Date());

        ArrayList noticeList = new ArrayList();
        noticeList.add(notice1);
        noticeList.add(notice2);
        noticeList.add(notice3);

        //显示
        for(int i=0;i<noticeList.size();i++){
            System.out.println(i+1+","+((Notice)(noticeList.get(i))).getTitle());//get方法的返回值是Object类型,没有get方法,Notice类有，此处需要强制类型转换
        }
        System.out.println("************");


        //在第一条公告后添加一条新公告
        Notice notice4 = new Notice(4,"在线编辑器","管理员",new Date());
        noticeList.add(1,notice4);
        for(int i=0;i<noticeList.size();i++){
            System.out.println(i+1+","+((Notice)(noticeList.get(i))).getTitle());//get方法的返回值是Object类型,没有get方法,Notice类有，此处需要强制类型转换
        }

        //删除
        System.out.println("************");
        //noticeList.remove(3);
        noticeList.remove(notice4);
        for(int i=0;i<noticeList.size();i++){
            System.out.println(i+1+","+((Notice)(noticeList.get(i))).getTitle());//get方法的返回值是Object类型,没有get方法,Notice类有，此处需要强制类型转换
        }

        //修改
        System.out.println("************");
        notice1.setTitle("欢迎来到java");
        noticeList.set(0,notice1);
        for(int i=0;i<noticeList.size();i++){
            System.out.println(i+1+","+((Notice)(noticeList.get(i))).getTitle());//get方法的返回值是Object类型,没有get方法,Notice类有，此处需要强制类型转换
        }
    }
}
